package name.fowler.refactoring.simplestore.reporter;

import java.util.LinkedList;
import java.util.List;

import name.fowler.refactoring.simplestore.Customer;
import name.fowler.refactoring.simplestore.movie.Movie;
import name.fowler.refactoring.simplestore.movie.Rent;

public class ReportStructureCreator {

	public ReportStructureCreator(){
	}
	
	public static List<String> getAllCustomersRentedMovies(List<Customer> customers){
		List<String> customersAllRentMoviesStructure = new LinkedList<String>();
		StringBuffer buffer;
		customersAllRentMoviesStructure.add("AllCustomersRentedMoviesStructure");
		for(Customer customer : customers){
			buffer = new StringBuffer();
			buffer.append(customer.getName()).append("\n");
			for (Rent rent : customer.getRents()){
				for (Movie movie : rent.getMovies()){
					buffer.append(movie.getTitle()).append("\n");
				}
			}
			customersAllRentMoviesStructure.add(buffer.toString());
			
		}
		return customersAllRentMoviesStructure;
	}
		
	public static List<String> getAllCustomersRentAmount(List<Customer> customers){
		List<String> customersAllRentMoviesStructure = new LinkedList<String>();
		StringBuffer buffer;
		double allCustomersRentAmount = 0;
		int allCustomersBonusPoints = 0;
		customersAllRentMoviesStructure.add("AllCustomersRentAmountStructure");
		for(Customer customer : customers){
			buffer = new StringBuffer();
			double customerRentAmount = 0;
			int customerBonusPoints = 0;
			buffer.append(customer.getName()).append("\n");
			for (Rent rent : customer.getRents()){
				customerRentAmount+=rent.getAllRentAmount();
				customerBonusPoints+=rent.getAllBonusPoints();
			}
			buffer.append(customerRentAmount).append("\n");
			buffer.append(customerBonusPoints).append("\n");
			customersAllRentMoviesStructure.add(buffer.toString());
			allCustomersRentAmount += customerRentAmount;
			allCustomersBonusPoints += customerBonusPoints;
		}
		customersAllRentMoviesStructure.add(String.valueOf(allCustomersRentAmount));
		customersAllRentMoviesStructure.add(String.valueOf(allCustomersBonusPoints));
		
		return customersAllRentMoviesStructure;
	}
}
